import 'package:flutter/material.dart';
import 'package:flutter_cate/ui/shared/app_theme.dart';
import 'package:flutter_cate/ui/shared/size_fit.dart';
import 'package:flutter_cate/core/router/router.dart';
import 'package:flutter_cate/core/viewmodel/meal_view_model.dart';
import 'package:flutter_cate/core/viewmodel/favor_view_model.dart';
import 'package:flutter_cate/core/viewmodel/filter_view_model.dart';
import 'package:provider/provider.dart';


void main() {
  runApp(

    MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (ctx) => AMFilterViewModel()),
        ChangeNotifierProxyProvider<AMFilterViewModel, AMMealViewModel>(
            create: (ctx) => AMMealViewModel(),
            update: (ctx, filterVM, mealVM) {
              mealVM.updateFilters(filterVM);
              return mealVM;
            },
        ),
        ChangeNotifierProxyProvider<AMFilterViewModel, AMFavorViewModel>(
            create: (ctx) => AMFavorViewModel(),
            update: (ctx, filterVM, favorVM) {
              favorVM.updateFilters(filterVM);
              return favorVM;
            }
        ),
      ],
      child: MyApp(),
    )
  );
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // AMSize 初始化
    AMSizeFit.initialize();

    return MaterialApp(
      title: "叮当菜谱",
      theme: AMAppTheme.norTheme,
      initialRoute: AMRouter.initialRoute,
      routes: AMRouter.routes,
      onGenerateRoute: AMRouter.generateRoute,
      onUnknownRoute: AMRouter.unknownRoute,
    );
  }
}
